/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.hiran.safewalker.helper;

import java.util.Random;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

/**
 *
 * @author Hiran
 */
public class WalkerSprite{

    private Sprite sprite;
    public int x=0,y=0;
    int maxWidth=200,maxHeight=200;
	boolean walkingToRight = true;
	int speed  = 5;
	float m = Float.parseFloat("0.25");
	int c;
    public WalkerSprite(Image img, int x, int y)
    {
		sprite = new Sprite(img, x, y);
		sprite.defineReferencePixel(sprite.getWidth()/2, sprite.getHeight());
		sprite.setFrameSequence(new int[]{20,21,22,23});
		selectRandomPos();
    }

    public void selectRandomPos()
    {
		Random r = new Random();
		r.setSeed(System.currentTimeMillis());
		x = r.nextInt(maxWidth);
		
		y = r.nextInt(maxHeight);
		if ((maxHeight-y)<30) y += 30;
    }

	public void nextStep()
	{
		if (x>=maxWidth) walkingToRight = false;
		if (x<=0) walkingToRight = true;
		if (walkingToRight)
			x += speed;
		else
			x -= speed;
	}

	public void paint(Graphics g)
	{
		sprite.setRefPixelPosition(x,y);
		sprite.nextFrame();
		sprite.paint(g);
	}

	public int getSpeed() {
		return speed;
	}

	public void setSpeed(int speed) {
		this.speed = speed;
	}



	public Sprite getSprite() {
		return sprite;
	}

	public void setSprite(Sprite sprite) {
		this.sprite = sprite;
	}
	
	public int getMaxHeight() {
		return maxHeight;
	}

	public void setMaxHeight(int maxHeight) {
		this.maxHeight = maxHeight;
	}

	public int getMaxWidth() {
		return maxWidth;
	}

	public void setMaxWidth(int maxWidth) {
		this.maxWidth = maxWidth;
	}
	
}
